package com.learn.multi_thread.C_ThreadPool.CustomizeThreadPool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class CachedThreadPool {
    /**
     * 没有上限的线程池
     * @param args 参数
     */
    public static void main(String[] args) {
        // 没有上线的线程池
        ExecutorService cacheThreadPool = Executors.newCachedThreadPool();
        threadPoolFactory(cacheThreadPool);

        // 有上限的线程池
//        ExecutorService fixedThreadPool = Executors.newFixedThreadPool(3);
//        threadPoolFactory(fixedThreadPool);


    }

    private static void threadPoolFactory(ExecutorService threadPool) {
        threadPool.submit(new MyThreadOfThreadPool());
        threadPool.submit(new MyThreadOfThreadPool());
        threadPool.submit(new MyThreadOfThreadPool());
        threadPool.submit(new MyThreadOfThreadPool());
        threadPool.submit(new MyThreadOfThreadPool());
        threadPool.submit(new MyThreadOfThreadPool());

        threadPool.shutdown();
    }

}
